package com.example.teamwork1.util;

import sun.misc.BASE64Encoder;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Common {
    public static String EncoderByMd5(String Code)
    {
        String privateKey="UxiaoTag";
        String NewCode;
        BASE64Encoder base64en = new BASE64Encoder();
        try {
            //Base64，md5加密字符
            NewCode= base64en.encode(md5(Code.getBytes()));
            NewCode= NewCode+privateKey;
            NewCode= base64en.encode(md5(NewCode.getBytes()));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return NewCode;
    }


    public static byte[] md5(byte[] data) {
        try {
            MessageDigest md = MessageDigest.getInstance("md5");
            return md.digest(data);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return new byte[]{};
    }

//
//    public static void main(String[] args) {
//        String a="123123123123";
//        System.out.println(EncoderByMd5(a));;
//    }

}
